﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ListForums : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Command_DeleteForum(Object sender, CommandEventArgs e)
    {
        if (e.CommandArgument != null)
        {
            string id = e.CommandArgument.ToString();
            TreasurerDataContext db = new TreasurerDataContext();

            //将其子栏目的父栏目设置为null
            var q1 = from aF in db.Forums
                     where aF.ParentID == id
                     select aF;
            foreach (Forums f in q1)
            {
                f.ParentID = null;
                f.Parent = null;
            }

            //移除属于该栏目的文章
            var q2 = from aA in db.Articles
                     where aA.ForumID == id
                     select aA;
            foreach (Articles a in q2)
            {
                a.ForumID = null;
                a.Forum = null;
            }

            var q3 = from aF in db.Forums
                     where aF.ID == id
                     select aF;

            db.Forums.DeleteAllOnSubmit(q3);
            db.SubmitChanges();

            ForumView.DataBind();

            ErrorText.Text = "已删除所选择的栏目信息。";
        }
    }
    protected void Command_ViewArticles(Object sender, CommandEventArgs e)
    {
        if (e.CommandArgument != null)
        {
            string id = e.CommandArgument.ToString();
            Response.Redirect("./ListArticles.aspx?fid=" + id);
        }
    }
    protected void NewForumButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Manage/EditForum.aspx");
    }
}